package com.tencent.iov.cowin.befsale.clue.controller.clue;

import com.tencent.iov.cowin.befsale.clue.controller.clue.assembler.DistributeRuleAssembler;
import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.request.AddDistributeRuleRequest;
import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.request.DeleteDistributeRuleRequest;
import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.request.QueryDistributeRuleRequest;
import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.request.UpdateDistributeRuleRequest;
import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.response.DistributeRuleResponse;
import com.tencent.iov.cowin.befsale.clue.domain.clue.po.DistributeRule;
import com.tencent.iov.cowin.befsale.clue.service.clue.DistributeRuleService;
import com.software.boot.common.entity.Response;
import com.software.boot.common.model.dao.PageRequest;
import com.software.boot.common.model.dao.PageResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Describe: 下发规则表_Controller层
 * @author: xuxiao.liu
 * @created: 2022-01-24 18:00:02
 * @version: 1.0
 */
@RestController
@RequestMapping(value = "/v1/demo/distributeRule", produces = MediaType.APPLICATION_JSON_VALUE)
@Api(tags = "下发规则表_Controller层")
public class DistributeRuleController{
	
	@Autowired
	private DistributeRuleService distributeRuleService;

	/**
	 * 通过ID获取详细信息
	 *
	 * @param: id
	 * @return: DistributeRule对象
	 */
	@ApiOperation(value = "DistributeRule管理-通过ID获取详细信息接口", httpMethod = "GET", response = Response.class, notes = "get_detail_by_id")
	@GetMapping(path = "/get_detail_by_id")
	public Response<DistributeRuleResponse> getDetailById(@ApiParam(required = true, value = "对象ID", defaultValue = "1")  @RequestParam("id") Long id) {
		return Response.success(DistributeRuleAssembler.transformPOToResponseVo(distributeRuleService.getDetailById(id), DistributeRuleResponse.class));
	}

	/**
	 * 单条数据插入DistributeRule
	 * @param request
	 * @return 插入的条数
	 */
	@ApiOperation(value = "DistributeRule管理-添加信息接口", httpMethod = "POST", response = Response.class, notes = "add")
	@PostMapping(path = "/add")
	public Response<Integer> add(@Valid @RequestBody AddDistributeRuleRequest request) {
		return Response.success(distributeRuleService.insert(DistributeRuleAssembler.transformVOToPO(request, DistributeRule.class)));
	}

	/**
	 * 批量插入DistributeRule
	 * @param requests
	 * @return 批量插入的条数
	 */
	@ApiOperation(value = "DistributeRule管理-批量插入DistributeRule接口", httpMethod = "POST", response = Response.class, notes = "add_batch")
	@PostMapping(path = "/add_batch")
	public Response<Integer> addBatch(@Valid @RequestBody List<QueryDistributeRuleRequest> requests) {
		return Response.success(distributeRuleService.insertBatch(DistributeRuleAssembler.transformPOToResponseVoList(requests, DistributeRule.class)));
	}

	/**
	 * 通过ID修改信息接口
	 *
	 * @param: request
	 * @return: 修改的条数
	 */
	@ApiOperation(value = "DistributeRule管理-修改信息接口", httpMethod = "POST", response = Response.class, notes = "update")
	@PutMapping(path = "/update")
	public Response<Integer> update(@Valid @RequestBody UpdateDistributeRuleRequest request) {
		return Response.success(distributeRuleService.update(DistributeRuleAssembler.transformVOToPO(request, DistributeRule.class)));
	}

	/**
	 * 通过ID删除数据
	 * @param request
	 * @return 删除的条数
	 */
	@ApiOperation(value = "DistributeRule管理-通过ID删除接口", httpMethod = "POST", response = Response.class, notes = "delete")
	@DeleteMapping(path = "/delete")
	public Response<Integer> delete(@Valid @RequestBody DeleteDistributeRuleRequest request) {
		return Response.success(distributeRuleService.delete(DistributeRuleAssembler.transformVOToPO(request, DistributeRule.class)));
	}

	/**
	 * 根据条件查询对象list列表
	 * @param request
	 * @return 查询结果
	 */
	@ApiOperation(value = "DistributeRule管理-根据条件查询对象list列表接口", httpMethod = "POST", response = Response.class, notes = "query_list_by_param")
	@PostMapping(path = "/get_list_by_param")
	public Response<List<DistributeRuleResponse>> getListByParam(@RequestBody QueryDistributeRuleRequest request) {
		List<DistributeRule> responseList = distributeRuleService.getListByParam(DistributeRuleAssembler.transformVOToPO(request, DistributeRule.class));
		return Response.success(DistributeRuleAssembler.transformPOToResponseVoList(responseList, DistributeRuleResponse.class));
	}

	/**
	 * 根据条件查询对象Page记录
	 * @param request
	 * @return 查询结果
	 */
	@ApiOperation(value = "DistributeRule管理-根据条件查询对象Page记录接口", httpMethod = "POST", response = Response.class, notes = "get_page_by_param")
	@PostMapping(value = "/get_page_by_param")
	public Response<PageResponse<DistributeRuleResponse>> getPageByParam(@RequestBody PageRequest<QueryDistributeRuleRequest> request) {
		PageResponse<DistributeRule> distributeRulePageResponse = distributeRuleService.getPageByParam(DistributeRuleAssembler.transformVOToPOPage(request, DistributeRule.class));
		return Response.success(DistributeRuleAssembler.transformPOToResponseVoPage(distributeRulePageResponse, DistributeRuleResponse.class));
	}

	/**
	 * 根据条件查询单个对象
	 * @param request
	 * @return 查询结果
	 */
	@ApiOperation(value = "DistributeRule管理-根据条件查询单个对象接口", httpMethod = "POST", response = Response.class, notes = "get_page_by_param")
	@PostMapping(value = "/get_one_by_param")
	public Response<DistributeRuleResponse> getOneByParam(@RequestBody QueryDistributeRuleRequest request){
		DistributeRule distributeRule = distributeRuleService.getOneByParam(DistributeRuleAssembler.transformVOToPO(request, DistributeRule.class));
		return Response.success(DistributeRuleAssembler.transformPOToResponseVo(distributeRule, DistributeRuleResponse.class));
	}
}